package com.cn.lyl.servlet.news;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.model.NewsModel;
import com.cn.lyl.service.NewsService;
import com.cn.lyl.service.impl.NewsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/news/add")
public class AddNewsServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String title = req.getParameter("title");
        String type = (req.getParameter("type"));
        String headPic = (req.getParameter("head_pic"));
        //String intro = req.getParameter("intro");
        String content= req.getParameter("content");
        System.out.println(type);
        NewsModel newsModel = new NewsModel();
        newsModel.setFace(headPic);
        newsModel.setTitle(title);
        newsModel.setContent(content);
        newsModel.setDependenceObj(type);
        NewsService newsService =new NewsServiceImpl();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result",newsService.addNews(newsModel));
        resp.getWriter().print(jsonObject);
    }
}
